<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="UTF-8" />
        <title>15_浅拷贝-特点</title>
    </head>
    <body>
        <script>
            var person = {
                name:'张馨予',
                age:36,
                hobby:['画画','养猫','养狗'],
                eat:function(){
                    console.log('鸡蛋');
                }
            }


            function lightCopy(person){
                var new_person = {};

                for(var x in person){
                    new_person[x] = person[x];
                }

                return new_person;

            }

            var np = lightCopy(person);

            console.log(person);
            console.log(np);

            // 如果拷贝的是基本数据类型，拷贝的就是基本数据类型的值；
            // 如果拷贝的是引用数据类型，拷贝的就是内存地址。

            person.name = '范冰冰';
            console.log(person.name);
            console.log(np.name);


            person.hobby[1] = '爱刘楠楠';
            console.log(person);
            console.log(np);


            console.log(person.hobby == np.hobby);
            console.log(person.eat == np.eat);


        </script>
    </body>
</html>